package com.pickme.food.controller;

import com.pickme.food.common.Res;
import com.pickme.food.pojo.dto.OrdersDto;
import com.pickme.food.service.inte.OpenService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 营业管理
 */
@Api(tags = "营业管理")
@Slf4j
@RestController
@RequestMapping("/open")
public class OpenController {

    @Autowired
    private OpenService openService;

    /**
     * 查询最近提交订单
     * @return
     */
    @GetMapping("/orders")
    public Res<List<OrdersDto>> selectRecent() {
        //log.info("营业管理======================");
        List<OrdersDto> ordersDtoList = openService.listRecentOrders();
        return Res.success(ordersDtoList);
    }

    @GetMapping("/takeCode")
    public Res<List<String>> selectTakeCode() {
        List<String> list = openService.listRecentTakeCode();
        return Res.success(list);
    }

    @PostMapping
    public Res<String> updateTake(@RequestBody String id) {
        openService.updateOrdersToTake(id);
        return Res.success("");
    }

    @GetMapping("/have")
    public Res<String> deleteTake(@RequestParam("takeCode") String takeCode) {
        openService.removeTakeCode(takeCode);
        return Res.success(takeCode + " 已取餐");
    }
}
